import { Numbers } from "./effect/Numbers.js";

class Clock {
    constructor(ms) {
        this.now = Date.now();
        this.events = [];
        this.ms = ms;
        this.running = false;
    }
    addEvent(event) {
        this.events.push(event);
    }
    update() {
        if (this.running) {
            this.next = Date.now();
            if (this.next - this.now >= this.ms) {
                this.events.forEach(e => {
                    e();
                })
                this.now = Date.now();
            } 
        }
    }
    run() {
        this.now = Date.now();
        this.running = true;
    }
    stop() {
        this.running = false;
    }
}

class Share {
    async init(resource, stage) {
        this.numbers = new Numbers(resource);
        await this.numbers.init();
        this.stage = stage;
    }

    getClock(ms) {
        return new Clock(ms);
    }

}
const share = new Share();
export default share;